<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>开关灯</title>
</head>

<body>
    <button>开关灯</button>
</body>
<script>
    color = ['black', 'white']
    l = true
    document.querySelector('button').onclick = function () {
        if (l)
            n = 0
        else
            n = 1
        l = !l
        document.body.style.backgroundColor = color[n]
    }
</script>

</html>